#include "SocketAddress.h"
#include "../Utils/DebugLog.h"



//====================================================================
//
//
//====================================================================
SocketAddress::SocketAddress(const char* ip, unsigned short port)
{
	memset(&address, 0, sizeof(address));
	address.sin_family = AF_INET;
	if(ip != "")
	{
		address.sin_addr.s_addr = inet_addr(ip);
		if(address.sin_addr.s_addr == INADDR_NONE)
		{
			DebugLog::getInstance()->log("SocketAddress::SocketAddress - the provided IP address seems to be invalid\n");
		}
	}
	if(port != 0)
	{
		address.sin_port = htons(port);
	}
}

//====================================================================
//
//
//====================================================================
SocketAddress::SocketAddress(sockaddr_in addr)
{
	address = addr;
}

//====================================================================
//
//
//====================================================================
SocketAddress::~SocketAddress()
{
	
}

//====================================================================
//
//
//====================================================================
void SocketAddress::setIp(const char* ip)
{
	address.sin_addr.s_addr = inet_addr(ip);
	if(address.sin_addr.s_addr == INADDR_NONE)
	{
		DebugLog::getInstance()->log("SocketAddress::setIp - the provided IP address seems to be invalid\n");
	}
}